package org.example.doctorapi.server.Imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.example.doctorapi.data.SysDept;
import org.example.doctorapi.data.SysDictData;
import org.example.doctorapi.mapper.SysDeptMapper;
import org.example.doctorapi.server.SysDeptServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysDeptServerImp implements SysDeptServer {
    @Autowired
    private SysDeptMapper sysDeptMapper;
    @Override
    public Page<SysDept> getDict(SysDept sysDept) {
        Page<SysDept> sysDeptPage = new Page<>();
        QueryWrapper<SysDept> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(sysDept.getDeptName()),SysDept.DEPT_NAME,sysDept.getDeptName());
        queryWrapper.eq(StringUtils.isNotBlank(sysDept.getStatus()),SysDept.STATUS,sysDept.getStatus());
        queryWrapper.like(StringUtils.isNotBlank(sysDept.getDeptNumber()),SysDept.DEPT_NUMBER,sysDept.getDeptNumber());
        List<SysDept> deptList = sysDeptMapper.selectList(queryWrapper);
        sysDeptPage.setRecords(deptList);
        sysDeptPage.setTotal(deptList.size());
        sysDeptPage.setCurrent(sysDept.getPageNum());
        sysDeptPage.setSize(sysDeptPage.getSize());
        return sysDeptPage;
    }

    @Override
    public void insertOne(SysDept sysDept) {
        sysDeptMapper.insert(sysDept);
    }

    @Override
    public void updateOne(SysDept sysDept) {
        sysDeptMapper.updateById(sysDept);
    }

    @Override
    public void deleteList(List<Integer> ids) {
        sysDeptMapper.deleteBatchIds(ids);
    }
}
